﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObserverAndMediator
{
    /// <summary>
    /// 产品事件
    /// </summary>
    public class ProductEvent : Observable
    {
        //事件起源
        private Product source;

        //事件的类型
        private ProductEventType type;

        /// <summary>
        /// 传入事件的源头，默认为新建类型
        /// </summary>
        /// <param name="p"></param>
        public ProductEvent(Product p) : this(p, ProductEventType.NEW_PRODUCT)
        {

        }

        /// <summary>
        /// 事件源头以及事件类型
        /// </summary>
        /// <param name="p"></param>
        /// <param name="_type"></param>
        public ProductEvent(Product p, ProductEventType _type)
        {
            this.source = p;
            this.type = _type;
            //事件触发
            notifyEventDispatch();
        }

        /// <summary>
        /// 获得事件的视作俑者
        /// </summary>
        public Product Source
        {
            get { return source; }
        }

        /// <summary>
        /// 获得事件的类型
        /// </summary>
        public ProductEventType EventType
        {
            get { return this.type; }
        }

        /// <summary>
        /// 通知事件处理中心
        /// </summary>
        public void notifyEventDispatch()
        {
            base.addObserver(EventDispatch.eventDispatch);
           
            base.notifyObservable(source);

        }
    }
}
